﻿@model FineAdmin.Model.FriendlyModel
@{ ViewBag.Title = "Edit";
    Layout = "~/Views/Shared/_LayoutForm.cshtml"; }
<form class="layui-form layui-form-pane ok-form" lay-filter="formTest">
    @*一些不需要更新的隐藏字段*@
    @Html.HiddenFor(x => x.Id)
    @Html.HiddenFor(x => x.CreateTime)
    @Html.HiddenFor(x => x.CreateUserId)
    <div class="layui-form-item">
        <label class="layui-form-label">名称</label>
        <div class="layui-input-block">
            <input type="text" name="Name" placeholder="名称" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">域名</label>
        <div class="layui-input-block">
            <input type="text" name="DomainName" placeholder="域名" autocomplete="off" class="layui-input" value="">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">指向</label>
        <div class="layui-input-block">
            <input type="text" id="Href" name="Href" placeholder="指向地址" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">简介</label>
        <div class="layui-input-block">
            <input type="text" id="Introduce" name="Introduce" placeholder="简单介绍" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">联系方式</label>
        <div class="layui-input-block">
            <input type="text" id="Phone" name="Phone" placeholder="手机/微信" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">邮件</label>
        <div class="layui-input-block">
            <input type="text" id="Mail" name="Mail" placeholder="电子邮件" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-block">
            <select name="State" lay-filter="aihao">
                <option value="1">正常</option>
                <option value="2">审核</option>
                <option value="3">废弃</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">排序码</label>
        <div class="layui-input-block">
            <input type="text" name="SortCode" placeholder="排序码" autocomplete="off" class="layui-input" lay-verify="number" maxlength="5">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="add">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>

</form>
<script>
    layui.use(["form", "element", "layedit", "treeSelect", "okLayer", "okUtils", 'laydate'], function () {
        let treeSelect = layui.treeSelect;
        let form = layui.form;
        let okLayer = layui.okLayer;
        let okUtils = layui.okUtils;
        var layedit = layui.layedit;
        var element = layui.element;
        var laydate = layui.laydate;
        //laydate.render({
        //    elem: '#Stime' //指定元素
        //    , type: 'datetime'
        //});
        //laydate.render({
        //    elem: '#Indate' //指定元素
        //    , type: 'datetime'
        //});
        layedit.set({
            uploadImage: {
                url: '@Url.Action("ExportFile", "PostSet")' //接口url
                , type: 'post' //默认post
            }
        });

        @*treeSelect.render({
            elem: "#Post_Type",
            data: "/Blog/BlogPostsCategorieSet/GetTreeSelect",
            type: "GET"
            @if (Model.CId!=0)
            {
                <text>,success: function (d) {
                treeSelect.checkNode('tree', "@Model.CId");
                treeSelect.refresh('tree');
                }</text>
            }
        });*@

        //给表单赋值
        form.val("formTest", { //formTest 即 class="layui-form" 所在元素属性 lay-filter="" 对应的值
            "Name": "@Model.Name",
            "DomainName": "@Model.DomainName",
            "Href": "@Model.Href",
            "Introduce": "@Model.Introduce",
            "Phone": "@Model.Phone",
            "Mail": "@Model.Mail",
            "SortCode": "@Model.SortCode",
            "State": "@Model.State",
           
        });

       

        form.on("submit(add)", function (data) {

           
            okUtils.ajax("/Blog/FriendlySet/Edit", "post", data.field, true).done(function (response) {
                okLayer.greenTickMsg(response.message, function () {
                    parent.location.reload(); // 父页面刷新
                    parent.layer.close(parent.layer.getFrameIndex(window.name));//先得到当前iframe层的索引 再执行关闭
                });
            }).fail(function (error) {
                console.log(error)
            });
            return false;
        });
    });
</script>

